package com.huaao.micropolice.core.model.content;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import com.huaao.micropolice.core.model.system.Dept;
import com.huaao.micropolice.core.model.system.User;


/**
 * @author qiyang
 * 科目表
 * @version 1.0
 */
public class Subject implements Serializable{
	
	private String id;
	private String code;
	private String name;
	private String image;
	private Integer sort;
	private Integer is_comment;
	private Integer is_audit;
	private Date createTime;
	private Date lastUpdateTime;
	private User creator;
	private User updater;
	private Integer status;
	private Dept dept;
	private String parent_ids;
	
	private Subject parent;
	private Set<Subject> children;
	private Set<Content> contents;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public Integer getIs_comment() {
		return is_comment;
	}
	public void setIs_comment(Integer is_comment) {
		this.is_comment = is_comment;
	}
	public Integer getIs_audit() {
		return is_audit;
	}
	public void setIs_audit(Integer is_audit) {
		this.is_audit = is_audit;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}
	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}
	public User getCreator() {
		return creator;
	}
	public void setCreator(User creator) {
		this.creator = creator;
	}
	public User getUpdater() {
		return updater;
	}
	public void setUpdater(User updater) {
		this.updater = updater;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public Dept getDept() {
		return dept;
	}
	public void setDept(Dept dept) {
		this.dept = dept;
	}
	public Subject getParent() {
		return parent;
	}
	public void setParent(Subject parent) {
		this.parent = parent;
	}
	public String getParent_ids() {
		return parent_ids;
	}
	public void setParent_ids(String parent_ids) {
		this.parent_ids = parent_ids;
	}
	public Set<Subject> getChildren() {
		return children;
	}
	public void setChildren(Set<Subject> children) {
		this.children = children;
	}
	public Set<Content> getContents() {
		return contents;
	}
	public void setContents(Set<Content> contents) {
		this.contents = contents;
	}
	public static void sortList(ArrayList<Subject> destList, List<Subject> sourceList, String parentId) {
		// TODO Auto-generated method stub
		for (int i=0; i<sourceList.size(); i++){
			Subject e = sourceList.get(i);
			if(e.getParent()==null){
				Subject p = new Subject();
				p.setId("0");
				e.setParent(p);
			}
			if (e.getParent()!=null && e.getParent().getId()!=null
					&& e.getParent().getId().equals(parentId)){
				destList.add(e);
				sortList(destList, sourceList, e.getId());
				// 判断是否还有子节点, 有则继续获取子节点
				/*for (int j=0; j<sourceList.size(); j++){
					Subject child = sourceList.get(j);
					if (child.getParent()!=null && child.getParent().getId()!=null
							&& child.getParent().getId().equals(e.getId())){
						sortList(destList, sourceList, e.getId());
						break;
					}
				}*/
			}
		}
	}
	public Integer getSort() {
		return sort;
	}
	public void setSort(Integer sort) {
		this.sort = sort;
	}
}
